<template>
        <el-container class="home-cotainer">
          <!-- 头部 -->
        <el-header>
             <div>
                <img src="../assets/heima.png" alt="">
                <span>逝者如斯夫  不舍昼夜</span>
             </div>
             <el-button type="success" @click="logout">退出</el-button>
        </el-header>
        <!-- 主体区域 -->
        <el-container>
            <!-- 左侧 -->
            <el-aside :width="isZheDie ? '64px' : '200px'">
                 <!-- 折叠菜单栏按钮 -->
                 <div class="toggle-button" @click="zhedie"> ✈✈✈ </div>
                 <el-menu 
                 router
                 background-color="#313743"
                  text-color="#fff"
                  active-text-color="#67c23a"
                   :collapse='isZheDie'
                   :collapse-transition = 'false'
                   >
                    <!-- 一级菜单 -->
                   <el-submenu :index="item.path " v-for="item in menuList" :key="item.id">
                    <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>{{item.authName}}</span>
                    </template>
                    <!-- 二级菜单 -->
                        <el-menu-item :index="erItem.path" v-for="erItem in item.children" :key="erItem.id">
                             <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>{{erItem.authName}}</span> 
                             </template>
                        </el-menu-item>
                   </el-submenu>
                </el-menu>
            </el-aside>
            <!-- 右侧 -->
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
        </el-container>
</template>

<script>
    export default {
        name:'homeIndex',
        data () {
            return {
                menuList:[],
                isZheDie:false
            }
        },
        created(){
            this.getMenuList()
        },
        methods: {
            logout(){
            window.sessionStorage.clear()
            this.$router.push('/login')
            },
           async getMenuList(){
                const {data:res} = await this.$http.get('/menus')
                if(res.meta.status !== 200) return this.$message.error(res.meta.msg)
                this.menuList = res.data
            },
            zhedie(){
              this.isZheDie = !this.isZheDie
            }
        }
    }
</script>

<style lang="less" scoped>
.home-cotainer {
    height: 100%;
}
     .el-header{
        display: flex;
        justify-content: space-between;
        background-color: #363d40;
        color: #fff;
        padding-left: 0px;
        align-items: center;
        font-size: 30px;
        div {
            display: flex;
            align-items: center;
        }
        span{
            margin-left: 20px;
        }
     }

    .el-aside {
         background-color: #313743;

         .toggle-button{
            background-color: #4A5064;
            text-align: center;
            cursor: pointer;
         }

         .el-menu{
             border-right: 0px;
         }
        
     }
     .el-main{
        background-color: #e9edf1;
     }
</style>